package cn.hfuu.socket;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class Client {
    public static void main(String[] args) {
        try {
            Socket s = new Socket("localhost", 9999);
            System.out.println(s + "连接了");
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            PrintWriter pw = new PrintWriter(out, true);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            Scanner input = new Scanner(System.in);
            while (true) {
                System.out.println("问吧：");
                String words = input.next();
                pw.println(words);
                String reply = br.readLine();
                System.out.println("服务器回复：" + reply);
                if (words.equals("byebye")) {
                    break;
                }
            }
            s.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
